namespace FolderCompare.Models;

public class CgDirectoryInfo : CgFileSystemInfo
{
        public CgDirectoryInfo() : base()
        { }

        public CgDirectoryInfo(DirectoryInfo info) : base(info)
        {
            Children = new ObservableCollection<CgFileSystemInfo>();
            foreach (var item in info.GetDirectories())
            {
                Children.Add(new CgDirectoryInfo(item));
            }

            foreach (var item in info.GetFiles())
            {
                Children.Add(new CgFileInfo(item));
            }
            IsDirectory = true;
        }

        public ObservableCollection<CgFileSystemInfo>? Children { get; set; }

        public override long? Length
        {
            get
            {
                if (Children.IsNullOrEmptyList())
                    return null;

                return Children.Sum(s => s.Length);
            }
        }
}